package cem.agony.model;

import java.util.Calendar;

import javafx.collections.FXCollections;
import javafx.collections.ObservableList;

public class Rider
{
    private final int number;
    private String firstName;
    private String lastName;

    private ObservableList<LogEntry> ridingLog = FXCollections.observableArrayList();
    private ObservableList<Sponsor> sponsors = FXCollections.observableArrayList();

    private int totalMiles = 0;

    public Rider( int number )
    {
        this.number = number;

//        ridingLog.add( new LogEntry( SagStation.LOYALTON, null, Calendar.getInstance() ) );
    }

    public Rider( int number, String firstName, String lastName )
    {
        this( number );

        this.firstName = firstName;
        this.lastName = lastName;
    }

    public void addMiles( int miles )
    {
        this.totalMiles += miles;
    }

    public int getMiles()
    {
        return totalMiles;
    }

    public void setFirstName( String firstName )
    {
        this.firstName = firstName;
    }

    public void setLastName( String lastName )
    {
        this.lastName = lastName;
    }

    public int getNumber()
    {
        return number;
    }

    public String getFirstName()
    {
        return firstName;
    }

    public String getLastName()
    {
        return lastName;
    }

    public String getFullName()
    {
        return firstName + " " + lastName;
    }

    public void addLogEntry( LogEntry entry )
    {
        ridingLog.add( entry );
    }

    public LogEntry getLatestStatus()
    {
        if ( ridingLog.isEmpty() )
        {
            return null;
        }

        return ridingLog.get( ridingLog.size() - 1 );
    }

    public ObservableList<LogEntry> getRidingLog()
    {
        return ridingLog;
    }

    public void addSponsor( Sponsor sponsor )
    {
        this.sponsors.add( sponsor );
    }

    public ObservableList<Sponsor> getSponsors()
    {
        return sponsors;
    }

    public double getTotalFlatRateAmount()
    {
        double total = 0.0;

        for ( Sponsor sponsor : sponsors )
        {
            total += sponsor.getFlatRateAmount();
        }

        return total;
    }

    public double getTotalPerMileAmount()
    {
        double total = 0.0;

        for ( Sponsor sponsor : sponsors )
        {
            total += sponsor.getPerMileAmount();
        }

        return total;
    }

    public double getTotalRaised()
    {
        double total = 0.0;

        for ( Sponsor sponsor : sponsors )
        {
            total += sponsor.getFlatRateAmount() + ( sponsor.getPerMileAmount() * totalMiles );
        }

        return total;
    }
}